$(document).ready(function(){
	var onSubmit = function(e){

			e.preventDefault();

			var form = $(this).parents('form');

			$.post(form.attr('action'), form.serialize(), function(data){
				if(data.status == 200){
					parent.window.location.href = data.redirect_link;
				}else{
					$('#flashes').html(data.message);
				}
			},'json');

			return false;
	};

	$('#login_form').submit(function(e){
		e.preventDefault();
		$('#submit_button').trigger('click');
		return false;
	});

	$('#submit_button').click(onSubmit);
});
